#pragma once


#include "CDMDevice.h"

//struct EMAP_PROPERTY
//{
//	DWORD		dwMapID;
//	CString		strMapName;
//	CString		strMapFilePath;
//	CPoint		ptPosition;
//	int			nHotSpotIcon;
//	DWORD		dwParentMapID;
//	int			nOrderInMap;
//};

//typedef vector<EMAP_PROPERTY> CEMapPropertyArray;

class CEMap;

typedef list<CEMap*> CEMapPtrList;
typedef hash_map<DWORD, CEMap*> CEMapPtrMap;

class CEMap
{
private:
	MapInfo m_MapProperty;
	CEMap* m_pParentMap;

	CEMapPtrList m_ChildMapList;
	//CDeviceList m_DeviceList;
	CChannelList m_ChannelList;
public:
	CEMap(MapInfo& MapProperty);
	~CEMap(void);

	inline DWORD GetMapID() const{
		return m_MapProperty.id;
	}

	inline DWORD GetParentMapID() const{
		return m_MapProperty.parentId;
	}

	inline CEMap* GetParentMap() const{
		return m_pParentMap;
	}

	inline LPCTSTR GetMapName() const{
		return m_MapProperty.mapname;
	}

	inline LPCTSTR GetMapURL() const{
		return m_MapProperty.url;
	}
	inline LPCTSTR GetMapFilePath() const{
		return m_MapProperty.picpath;
	}

	//inline int GetOrderInMap() const{
	//	return m_MapProperty.nOrderInMap;
	//}

	//BOOL SetOrderInMap(int nOrder);

	void GetMapProperty(MapInfo* pProperty) const;
	BOOL UpdateMapProperty(MapInfo& MapProperty, std::string pData);

	BOOL AddChildMap(CEMap* pMap);
	void SetParentMap(CEMap* pParentMap);
	void RemoveMap(CEMap* pMap);

	void SortChildMapList();

	BOOL IncreaseOrder(CEMap* pMap);
	BOOL DecreaseOrder(CEMap* pMap);

	BOOL IsTopOrder(CEMap* pMap);
	BOOL IsBottomOrder(CEMap* pMap);

	inline const CEMapPtrList& GetChildMapList() const{
		return m_ChildMapList;
	}
	inline int GetChildMapNumber() const{
		return static_cast<int>(m_ChildMapList.size());
	}

	//0407
	//BOOL AddDevice(CCDMDevice* pDevice);
	//BOOL RemoveDevice(CCDMDevice* pDevice);

	//inline const list<CDevice*>& GetDeviceList() const{
	//	return m_DeviceList;
	//}
	//inline int GetDeviceNumber() const{
	//	return static_cast<int>(m_DeviceList.size());
	//}
	BOOL AddChannel(CChannel* pChannel);
	BOOL RemoveChannel(CChannel* pChannel);

	inline const list<CChannel*>& GetChannelList() const{
		return m_ChannelList;
	}
	inline int GetChannelNumber() const{
		return static_cast<int>(m_ChannelList.size());
	}
};
